/*
 *  MiloInnovation.h
 *  Milovo04alfa00
 *
 *  Created by Luca on 24/11/06.
 *  Copyright 2006 __MyCompanyName__. All rights reserved.
 *
 */

#ifndef MILOINNOVATION_H
#define MILOINNOVATION_H

#include "MilovoTables.h"
#include "MilovoCommonFuncs.h"


bool TryInnovation(MilinitParams &,  SystemParams &, Mil_Int , Agents *, Recipes *, Artifacts *, MilovoRandom &, int);
bool InnovationWithoutGoal(MilinitParams &,  SystemParams &, Mil_Int , Agents *, Recipes *, Artifacts *, MilovoRandom &, Mil_Int, int);
bool InnovationWithGoal(Mil_Int , MilinitParams &,  SystemParams &, vector<Mil_Int> &, Agents *, Recipes *, Artifacts *, MilovoRandom &, MilovoEnvironment &);
Mil_Int SelectGoalThisAgent(vector<Mil_Int> &, Agents *, Recipes *, Artifacts *, Requests *, MilovoRandom &, MilovoEnvironment &);
bool InitGeneticPopulationRecipes(MilinitParams &, SystemParams &, GeneticRecipes &, vector<Mil_Int> &, Agents *, Recipes *, Artifacts *, MilovoRandom &, int);
bool InitRandomGeneticPopulationRecipes(MilinitParams &, SystemParams &, GeneticRecipes &, vector<Mil_Int> &, Agents *, Recipes *, Artifacts *, MilovoRandom &, int);
Mil_Int CalcFitness(GeneticRecipes &, Mil_Int, Artifacts *, int);
void SelectParents(GeneticRecipes &, vector<Mil_Int> &, MilovoRandom &, int);
void CrossOver(GeneticRecipes &, GeneticRecipes &, vector<Mil_Int> &, MilovoRandom &, int);
void CutSelectedRecipesForCrossOver(Mil_Int , GeneticRecipes &, list<Mil_Int> &, list<Mil_Int> &, list<Mil_Int> &, list<Mil_Int> &, Mil_Int , MilovoRandom &, int);
void UpdateGeneticPopulationRecipes(GeneticRecipes &, GeneticRecipes &, int);
Mil_Int CheckForIDRecipeWithMaxFitness(GeneticRecipes &, Mil_Double , int);
Mil_Int SelectPartnerInnovatorForThisAgent(Mil_Int , Agents *, MilovoRandom &, int);
void PrintGeneticPopulation(GeneticRecipes &, Artifacts *);
void PrintGeneticPopulationTofile(GeneticRecipes &, Artifacts *, SimulationParams &, MilovoEnvironment &, Mil_Int , Mil_Int, Mil_Int);
Mil_Int GetCuttingPointThoseRecipes(vector<Mil_Int> &, GeneticRecipes &, MilovoRandom &, int);
bool CheckThisGoalWithAgentsOutputs(Mil_Int tmpGoalSelected, Mil_Int tmpIDAgentsToAnalize, Agents *tmp_CurrentTabAgents, 
												Recipes *tmp_CurrentTabRecipes, Artifacts *tmp_CurrentTabArtifacts, int tmp_CurrentDebugLevel);
vector<Mil_Int> ExtractAgentsOutputsName(Mil_Int tmpCurrentIDAgentToAnalize, Agents *tmp_CurrentTabAgents, Recipes *tmp_CurrentTabRecipes, 
													 Artifacts *tmp_CurrentTabArtifacts, Mil_Int tmp_CurrentDebugLevel);
void SelectGoalFromRequest(vector<Mil_Int> &tmpVectGoalSelectedFromRequest, Mil_Int tmpIDAgentToAnalize, Agents *tmp_CurrentTabAgents, 
									Requests *tmp_CurrentTabRequests, MilovoRandom &, MilovoEnvironment &);

#endif



